package com.wang.set;

import java.util.HashSet;
import java.util.Iterator;

/**
 * hashset 集合的使用
 * 存储结构:哈希表(数组+链表+(在jdk1.8之后又加入了红黑树))
 */
public class HashSetDemo {
    public static void main(String[] args) {
        HashSet<String> hashSet = new HashSet<>();
        hashSet.add("b");
        hashSet.add("c");
        hashSet.add("a");
        System.out.println(hashSet.toString());
        System.out.println(hashSet.size());
        //删除 hashSet("a")
        //foreach
        for (String s : hashSet) {
            System.out.println(s);
        }
        //iterator
        Iterator<String> iterator = hashSet.iterator();
        while (iterator.hasNext())System.out.println(iterator.next());
        //contains
        System.out.println(hashSet.contains("a"));
        System.out.println(hashSet.isEmpty());
    }
}
